package com.lck.tutor.controller;

import com.lck.tutor.common.BaseResponse;
import com.lck.tutor.model.domain.Follow;
import com.lck.tutor.model.domain.User;
import com.lck.tutor.service.FollowService;
import com.lck.tutor.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author:鹿存岿
 * @date 2022/10/30 16:55
 */
@RestController
@RequestMapping("/follow")
public class FollowController {

    @Resource
    private FollowService followService;

    @Resource
    private UserService userService;

    @PostMapping("/{id}/{isFollow}")
    public BaseResponse<?> follow(@PathVariable("id") Long id, @PathVariable("isFollow") Boolean isFollow, HttpServletRequest request){
        User loginUser = userService.getLoginUser(request);
        return followService.follow(id, isFollow,loginUser);
    }

    @GetMapping("/common/{id}")
    public BaseResponse<List<User>> common(@PathVariable ("id") Long id,HttpServletRequest request){
        User loginUser = userService.getLoginUser(request);
        Long userId = loginUser.getId();
        return followService.common(id, userId);
    }
}
